package com.aaa.service.impl;

import com.aaa.dao.MenuDao;
import com.aaa.entity.Menu;
import com.aaa.service.MenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MenuServiceImpl extends ServiceImpl<MenuDao, Menu> implements MenuService {
    @Resource
    private MenuDao menuDao;
    @Override
    public List<Menu> listMyMenus(Integer uid) {
        //先查询用户能操作的一级菜单
        List<Menu> oneMenus = menuDao.listOneMens(uid);
        //遍历所有用户能操作的一级菜单
        for (Menu oneMenu:oneMenus){
            //去查询用户能操作的某个一级菜单下的二级菜单
            List<Menu> twoMenus = menuDao.listTwoMens(uid, oneMenu.getMid());

            //把用户能操作的某个一级菜单下的二级菜单 设置到一级菜单的children属性中
            oneMenu.setChildren(twoMenus);
        }
        return oneMenus;
    }

    @Override
    public List<String> ListUserPermits(Integer uid) {
        return menuDao.ListUserPermits(uid);
    }

    @Override
    public List<Menu> listAllMenus() {
        //先查询所有的一级菜单
        List<Menu> oneMenus = menuDao.listAllOneMens();
        //遍历一级菜单
        for (Menu oneMenu:oneMenus){
            //根据一级菜单的id 查询所有的二级菜单
            List<Menu> twoMenus = menuDao.listAllTwoMens(oneMenu.getMid());
            //把查询出来的二级菜单 设置到一级菜单的children属性中
            oneMenu.setChildren(twoMenus);

        }


        return oneMenus;
    }
}
